package com.pig4cloud.pig.admin.enums;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.pig4cloud.pig.common.core.constant.CommonConstants;
import com.pig4cloud.pig.common.core.constant.enums.FieldType;
import com.pig4cloud.pig.common.security.service.PigUser;
import com.pig4cloud.pig.common.security.util.SecurityUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.time.LocalDateTime;
import java.util.function.Supplier;

/**
 * @author mobai
 */

@Getter
@AllArgsConstructor
/**


 metaFieldEntity.setUpdatable(0);
 metaFieldEntity.setCreatable(0);
 metaFieldEntity.setNullable(0);
 metaFieldEntity.setSystemFieldFlag(CommonConstants.YES);
 */ public enum BaseFieldType {
	ID("id", "主键", FieldType.INPUT.getValue(), 0, 0, 0, 1, IdUtil::getSnowflakeNextId),
	CREATE_BY("create_by", "创建人", FieldType.INPUT.getValue(), 1, 1, 1, 1, () -> {
		PigUser user = SecurityUtils.getUser();
		if (ObjectUtil.isNull(user)) {
			return "";
		}
		return SecurityUtils.getUser().getUsername();
	}),
	CREATE_TIME("create_time", "创建时间", FieldType.DATE_PICKER.getValue(), 1, 1, 1, 1, LocalDateTime::now),
	UPDATE_BY("update_by", "修改人", FieldType.INPUT.getValue(), 1, 1, 1, 1, () -> {
		PigUser user = SecurityUtils.getUser();
		if (ObjectUtil.isNull(user)) {
			return "";
		}
		return SecurityUtils.getUser().getUsername();
	}),
	UPDATE_TIME("update_time", "修改时间", FieldType.DATE_PICKER.getValue(), 1, 1, 1, 1, LocalDateTime::now),
	DEL_FLAG("del_flag", "删除标记", FieldType.INPUT_NUMBER.getValue(), 1, 1, 1, 1, () -> CommonConstants.NO),
	PROCESS_INSTANCE_ID("process_instance_id", "流程实例id", FieldType.INPUT.getValue(), 1, 1, 1, 1, () -> "");

	private final String label;
	private final String name;
	private final String type;
	private final Integer creatable;
	private final Integer updatable;
	private final Integer nullable;
	private final Integer systemFieldFlag;
	private final Supplier<?> defaultValue;

}
